/**
 * Created by seeker910 on 2017/7/26.
 */
Rsd.define('Rsd.common.Lang', {
    extend:'Rsd.common.Object',
    singleton:true,
    "static":function __init(callback) {

        Rsd.resources = Rsd.resources ||{};
        Rsd.resources.lang = Rsd.resources.lang||{};

        if(callback)
        {
            callback.call();
        }
    },

    /*
     * */
    constructor: function Lang(config) {
        //debugger;
        this.apply(config);

    },
    /*
    * 加载语言包
    * */
    load:function (name) {

       var _lang = name||'zh-cn'
       this.langName = _lang;
       var url = Rsd.getRedjsUrl('/resources/lang/'+ _lang +'.js?t=' + Rsd.timestamp);

        Rsd.loadScriptFile(url);
  
    },
    /*
    * */
    get:function get(name) {
  
        var lang = Rsd.resources.lang||{}; 
        var lang = lang[this.langName];
        
        var arr = name.split('.');
        for (var i in arr) { 
            if(lang==null )
            {
                break;
            }
            lang = lang[arr[i]];
        }
        return lang;
    }
});